﻿// (c) Norbert Huffschmid
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace SpinDotters.Widgets.Converter
{
    public class BoolToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value.GetType() != typeof(bool))
                throw new ArgumentException("value must be bool");

            bool visibility = (bool)value;
            bool invert = false;
            if ((parameter != null) && parameter.ToString().Equals("Invert"))
                invert = true;

            if (((visibility == true) && !invert) ||
                ((visibility == false) && invert))
            {
                return Visibility.Visible;
            }
            else
            {
                return Visibility.Collapsed;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
